package com.app.couponsharelife.ui.adapter

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.databinding.DataBindingUtil
import com.app.couponsharelife.R
import com.app.couponsharelife.databinding.WelcomeTabItemBinding

/**
 * Created by guluwa on 2018/11/28.
 */
class WelcomeIndicatorAdapter(var pos: Int,
                              private val list: List<Any>) :
        androidx.recyclerview.widget.RecyclerView.Adapter<androidx.recyclerview.widget.RecyclerView.ViewHolder>() {

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): androidx.recyclerview.widget.RecyclerView.ViewHolder {
        return ViewHolder(DataBindingUtil.inflate(
                LayoutInflater.from(parent.context), R.layout.welcome_tab_item, parent, false))
    }

    override fun getItemCount(): Int {
        return list.size
    }

    override fun onBindViewHolder(holder: androidx.recyclerview.widget.RecyclerView.ViewHolder, position: Int) {
        holder as ViewHolder
        if (position != pos) {
            holder.databinding.mIndicatorViewSelect.visibility = View.GONE
            holder.databinding.mIndicatorViewNoSelect.visibility = View.VISIBLE
        } else {
            holder.databinding.mIndicatorViewSelect.visibility = View.VISIBLE
            holder.databinding.mIndicatorViewNoSelect.visibility = View.GONE
        }
    }

    inner class ViewHolder(val databinding: WelcomeTabItemBinding) : androidx.recyclerview.widget.RecyclerView.ViewHolder(databinding.root)
}